---------------------------------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  /Users/Jeff/Dropbox/TermLimits/Replication/Models/Military/Conditional/ServiceType/PredictedValues.log
  log type:  text
 opened on:  12 Nov 2016, 22:07:51

. cd "/Users/Jeff/Dropbox/TermLimits/Replication/Models/Military/Conditional/ServiceType";
/Users/Jeff/Dropbox/TermLimits/Replication/Models/Military/Conditional/ServiceType

. **************************************************************;
. *Author: Jeff Carter                                         *;
. *Date: Monday, November 23, 2015  12:12                             *;
. *Purpose: Simulating Predictions                *;
. **************************************************************;
. *********************************;
. **      Peace to War            *;
. *********************************;
. use "/Users/Jeff/Dropbox/TermLimits/Replication/Models/Military/Conditional/ServiceType/SimData.dta";

. postutil clear;

. postfile mypost prob_hat0 lo0 hi0 prob_hat1 lo1 hi1 diff_hat0 diff_lo0 diff_hi0
>                 prob_hat01 lo01 hi01 prob_hat11 lo11 hi11 diff_hat01 diff_lo01 diff_hi01
>                 prob_hat02 lo02 hi02 prob_hat12 lo12 hi12 diff_hat02 diff_lo02 diff_hi02
>                 delta_hat delta_lo delta_hi
>                 delta_hat1 delta_lo1 delta_hi1 using PredictedValues, replace;
(note: file PredictedValues.dta not found)

. noisily display "start";
start

. local a=0 ;

. while `a' < .1 { ;
  2. {;
  3. scalar h_Accountable =   0  ;
  4. scalar h_LameDuck= 1  ;
  5. scalar h_Civilian = 0;
  6. scalar h_Military = 1;
  7. scalar h_Constant = 1;
  8. scalar h_NonCombat = 1;
  9. scalar h_Combat = 1;
 10.  scalar h_Parliament = 0;
 11. scalar h_CivilWar = 0;
 12. scalar h_GDPpc =  12589.35;
 13. scalar h_Growth = 3.453132;
 14. scalar h_MajorPower = 0;
 15. scalar h_Borders = 2;
 16. scalar h_Mobilization =  -.0008714 ;
 17. scalar h_Time = 5;
 18.  scalar h_Rivalry = 0;
 19. scalar h_Female = 0;
 20. generate x_betahat0 = MG_b1*h_Accountable
>     + MG_b2*h_Civilian
>     + MG_b3*(h_Accountable*h_Civilian)
>     + MG_b4*h_Civilian
>     + MG_b5*(h_Accountable*h_Civilian)
>     + MG_b6*h_Rivalry
>     + MG_b7*h_Borders
>     + MG_b8*h_Parliament
>     + MG_b9*h_Female
>     + MG_b10*h_Time
>     + MG_b11*(h_Time^2)
>     + MG_b12*(h_Time^3)
>     + MG_b13*h_Constant;
 21. generate x_betahat1 = MG_b1* h_LameDuck
>     + MG_b2*h_Civilian
>     + MG_b3*(h_LameDuck*h_Civilian)
>     + MG_b4*h_Civilian
>     + MG_b5*(h_LameDuck*h_Civilian)
>     + MG_b6*h_Rivalry
>     + MG_b7*h_Borders
>     + MG_b8*h_Parliament
>     + MG_b9*h_Female
>     + MG_b10*h_Time
>     + MG_b11*(h_Time^2)
>     + MG_b12*(h_Time^3)
>     + MG_b13*h_Constant;
 22.  gen prob0=1/(1+exp(-x_betahat0));
 23. gen prob1=1/(1+exp(-x_betahat1));
 24.  gen diff0=prob1-prob0 ;
 25. egen probhat0=mean(prob0) ;
 26. egen probhat1=mean(prob1) ;
 27. egen diffhat0=mean(diff0) ;
 28. generate x_betahat01 =   MG_b1*h_Accountable
>     + MG_b2*h_NonCombat
>     + MG_b3*(h_Accountable*h_NonCombat)
>     + MG_b4*h_Civilian
>     + MG_b5*(h_Accountable*h_Civilian)
>     + MG_b6*h_Rivalry
>     + MG_b7*h_Borders
>     + MG_b8*h_Parliament
>     + MG_b9*h_Female
>     + MG_b10*h_Time
>     + MG_b11*(h_Time^2)
>     + MG_b12*(h_Time^3)
>     + MG_b13*h_Constant;
 29.  generate x_betahat11 =   MG_b1* h_LameDuck
>     + MG_b2*h_NonCombat
>     + MG_b3*(h_LameDuck*h_NonCombat)
>     + MG_b4*h_Civilian
>     + MG_b5*(h_LameDuck*h_Civilian)
>     + MG_b6*h_Rivalry
>     + MG_b7*h_Borders
>     + MG_b8*h_Parliament
>     + MG_b9*h_Female
>     + MG_b10*h_Time
>     + MG_b11*(h_Time^2)
>     + MG_b12*(h_Time^3)
>     + MG_b13*h_Constant;
 30.   gen prob01=1/(1+exp(-x_betahat01));
 31. gen prob11=1/(1+exp(-x_betahat11));
 32. gen diff01=prob11-prob01 ;
 33. egen probhat01=mean(prob01) ;
 34. egen probhat11=mean(prob11) ;
 35. egen diffhat01=mean(diff01) ;
 36. generate x_betahat02 =   MG_b1*h_Accountable
>     + MG_b2*h_Civilian
>     + MG_b3*(h_Accountable*h_Civilian)
>     + MG_b4*h_Combat
>     + MG_b5*(h_Accountable*h_Combat)
>     + MG_b6*h_Rivalry
>     + MG_b7*h_Borders
>     + MG_b8*h_Parliament
>     + MG_b9*h_Female
>     + MG_b10*h_Time
>     + MG_b11*(h_Time^2)
>     + MG_b12*(h_Time^3)
>     + MG_b13*h_Constant;
 37.  generate x_betahat12 =   MG_b1* h_LameDuck
>     + MG_b2*h_Civilian
>     + MG_b3*(h_LameDuck*h_Civilian)
>     + MG_b4*h_Combat
>     + MG_b5*(h_LameDuck*h_Combat)
>     + MG_b6*h_Rivalry
>     + MG_b7*h_Borders
>     + MG_b8*h_Parliament
>     + MG_b9*h_Female
>     + MG_b10*h_Time
>     + MG_b11*(h_Time^2)
>     + MG_b12*(h_Time^3)
>     + MG_b13*h_Constant;
 38.   gen prob02=1/(1+exp(-x_betahat02));
 39. gen prob12=1/(1+exp(-x_betahat12));
 40. gen diff02=prob12-prob02 ;
 41. egen probhat02=mean(prob02) ;
 42. egen probhat12=mean(prob12) ;
 43. egen diffhat02=mean(diff02) ;
 44.  gen delta=diff01-diff0;
 45. gen delta1=diff02-diff0;
 46.  egen deltahat=mean(delta);
 47. egen deltahat1=mean(delta1);
 48. tempname prob_hat0 lo0 hi0 prob_hat1 lo1 hi1 diff_hat0 diff_lo0 diff_hi0
>          prob_hat01 lo01 hi01 prob_hat11 lo11 hi11 diff_hat01 diff_lo01 diff_hi01
>          prob_hat02 lo02 hi02 prob_hat12 lo12 hi12 diff_hat02 diff_lo02 diff_hi02
>          delta_hat delta_lo delta_hi
>          delta_hat1 delta_lo1 delta_hi1;
 49.     _pctile prob0, p(2.5,97.5) ;
 50.     scalar `lo0'=r(r1) ;
 51.     scalar `hi0'=r(r2) ;
 52.     _pctile prob1, p(2.5,97.5) ;
 53.     scalar `lo1'=r(r1) ;
 54.     scalar `hi1'=r(r2) ;
 55.     _pctile diff0, p(2.5,97.5) ;
 56.     scalar `diff_lo0'= r(r1) ;
 57.     scalar `diff_hi0'=r(r2) ;
 58.     scalar `prob_hat0'=probhat0 ;
 59.     scalar `prob_hat1'=probhat1 ;
 60.     scalar `diff_hat0'=diffhat0 ;
 61.        _pctile prob01, p(2.5,97.5) ;
 62.     scalar `lo01'=r(r1) ;
 63.     scalar `hi01'=r(r2) ;
 64.     _pctile prob11, p(2.5,97.5) ;
 65.     scalar `lo11'=r(r1) ;
 66.     scalar `hi11'=r(r2) ;
 67.     _pctile diff01, p(2.5,97.5) ;
 68.     scalar `diff_lo01'= r(r1) ;
 69.     scalar `diff_hi01'=r(r2) ;
 70.     scalar `prob_hat01'=probhat01 ;
 71.     scalar `prob_hat11'=probhat11 ;
 72.     scalar `diff_hat01'=diffhat01 ;
 73.        _pctile prob02, p(2.5,97.5) ;
 74.     scalar `lo02'=r(r1) ;
 75.     scalar `hi02'=r(r2) ;
 76.     _pctile prob12, p(2.5,97.5) ;
 77.     scalar `lo12'=r(r1) ;
 78.     scalar `hi12'=r(r2) ;
 79.     _pctile diff02, p(2.5,97.5) ;
 80.     scalar `diff_lo02'= r(r1) ;
 81.     scalar `diff_hi02'=r(r2) ;
 82.     scalar `prob_hat02'=probhat02 ;
 83.     scalar `prob_hat12'=probhat12 ;
 84.     scalar `diff_hat02'=diffhat02 ;
 85.      _pctile delta, p(2.5,97.5) ;
 86.     scalar `delta_lo'= r(r1) ;
 87.     scalar `delta_hi'=r(r2) ;
 88.      _pctile delta1, p(2.5,97.5) ;
 89.     scalar `delta_lo1'= r(r1) ;
 90.     scalar `delta_hi1'=r(r2) ;
 91.      scalar `delta_hat'=deltahat;
 92.     scalar `delta_hat1'=deltahat1;
 93.     post mypost (`prob_hat0') (`lo0') (`hi0') (`prob_hat1') (`lo1') (`hi1') (`diff_hat0') (`diff_lo0') (`diff_hi0')
>                 (`prob_hat01') (`lo01') (`hi01') (`prob_hat11') (`lo11') (`hi11') (`diff_hat01') (`diff_lo01') (`diff_hi0
> 1')
>                 (`prob_hat02') (`lo02') (`hi02') (`prob_hat12') (`lo12') (`hi12') (`diff_hat02') (`diff_lo02') (`diff_hi0
> 2')
>                 (`delta_hat') (`delta_lo') (`delta_hi')
>                 (`delta_hat1') (`delta_lo1') (`delta_hi1')
> 
>     ;
 94.     } ;
 95.     drop    x_betahat0 x_betahat1 prob0 prob1 diff0 probhat0 probhat1 diffhat0
>             x_betahat01 x_betahat11 prob01 prob11 diff01 probhat01 probhat11 diffhat01
>             x_betahat02 x_betahat12 prob02 prob12 diff02 probhat02 probhat12 diffhat02
>             delta deltahat
>             delta1 deltahat1;
 96.     local a=`a'+ .1 ;
 97.     display "." _c ;
 98.     } ;
.
. display "" ;


.  postclose mypost ;

. use PredictedValues, clear;

. sum;

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
   prob_hat0 |         1    .0523245           .   .0523245   .0523245
         lo0 |         1    .0353319           .   .0353319   .0353319
         hi0 |         1    .0745468           .   .0745468   .0745468
   prob_hat1 |         1    .0270478           .   .0270478   .0270478
         lo1 |         1    .0167118           .   .0167118   .0167118
-------------+--------------------------------------------------------
         hi1 |         1    .0411729           .   .0411729   .0411729
   diff_hat0 |         1   -.0252767           .  -.0252767  -.0252767
    diff_lo0 |         1   -.0457668           .  -.0457668  -.0457668
    diff_hi0 |         1    -.007808           .   -.007808   -.007808
  prob_hat01 |         1    .0785896           .   .0785896   .0785896
-------------+--------------------------------------------------------
        lo01 |         1    .0424253           .   .0424253   .0424253
        hi01 |         1    .1298746           .   .1298746   .1298746
  prob_hat11 |         1    .1072198           .   .1072198   .1072198
        lo11 |         1    .0320443           .   .0320443   .0320443
        hi11 |         1    .2517166           .   .2517166   .2517166
-------------+--------------------------------------------------------
  diff_hat01 |         1    .0286301           .   .0286301   .0286301
   diff_lo01 |         1   -.0612321           .  -.0612321  -.0612321
   diff_hi01 |         1    .1748131           .   .1748131   .1748131
  prob_hat02 |         1    .0740991           .   .0740991   .0740991
        lo02 |         1    .0459582           .   .0459582   .0459582
-------------+--------------------------------------------------------
        hi02 |         1    .1114239           .   .1114239   .1114239
  prob_hat12 |         1    .0308607           .   .0308607   .0308607
        lo12 |         1    .0045358           .   .0045358   .0045358
        hi12 |         1    .1073395           .   .1073395   .1073395
  diff_hat02 |         1   -.0432385           .  -.0432385  -.0432385
-------------+--------------------------------------------------------
   diff_lo02 |         1   -.0898133           .  -.0898133  -.0898133
   diff_hi02 |         1    .0331168           .   .0331168   .0331168
   delta_hat |         1    .0539069           .   .0539069   .0539069
    delta_lo |         1   -.0358254           .  -.0358254  -.0358254
    delta_hi |         1    .2007324           .   .2007324   .2007324
-------------+--------------------------------------------------------
  delta_hat1 |         1   -.0179618           .  -.0179618  -.0179618
   delta_lo1 |         1   -.0625267           .  -.0625267  -.0625267
   delta_hi1 |         1    .0598486           .   .0598486   .0598486

. saveold PredictedValues, replace;
file PredictedValues.dta saved

. log close;
      name:  <unnamed>
       log:  /Users/Jeff/Dropbox/TermLimits/Replication/Models/Military/Conditional/ServiceType/PredictedValues.log
  log type:  text
 closed on:  12 Nov 2016, 22:07:51
---------------------------------------------------------------------------------------------------------------------------
